树莓派5刷Raspberry Pi OS和其他功能


更新日期

2025.06.30

完成功能

注意,连接树莓派的typec线和充电器支持pd
原装充电器5.1v5a,不要用太垃圾的充电器,会经常红灯无法启动
信号不太好,不要离wifi太远
需要一些linux命令行基础
docker和其他一些功能,可能需要路由器翻墙
参考文章https://andi.wang/go?id=36
部分软件分享https://pan.baidu.com/s/1uvgT0eSmNST-e_ymBcDWBw?pwd=nmqx

使用raspberry pi imager在tf写入系统

使用raspberry pi imager,https://downloads.raspberrypi.org/imager/imager_latest.exe
如果之前有其他系统,可以先在操作系统里最下面选择格式化下一步,再选需要的系统
树莓派设置:raspberry pi 5
操作系统:raspberry pi os 64bit,只命令行无界面的话选raspberry pi os other,raspberry pi os lite 64bit
存储设置:选择你的tf卡目录
下一步,编辑设置
通用:

  • 主机名,用户名密码,配置wlan
  • 本地化设置:时区Asia/Shanghai
    服务:
  • 开启ssh,使用密码登录
    保存,确认,确认

启动后发现还是没法ssh连接

使用minihdmi连接屏幕,鼠标,右上角wifi设置country选择china,就自动连接了,看来还是有bug,写镜像的时候没找到设置country的

设置

不带屏幕和键盘的树莓派开启ssh

如果写入系统时没开启ssh服务,电脑上读取tf卡,bootfs分区,新建一个文件,文件名ssh,没有扩展名,没有内容

设置风扇转速

如果安装了带风扇的壳,线连接在最外面的usb口旁边,可以控制转速
使用windows的文本编辑器可能会导致树莓派无法启动,建议才linux下编辑
bootfs分区,编辑config.txt,最后添加

1
2
3
4
5
dtparam=cooling_fan=on
dtparam=fan_temp0=42000,fan_temp0_hyst=2000,fan_temp0_speed=100
dtparam=fan_temp1=50000,fan_temp1_hyst=5000,fan_temp1_speed=150
dtparam=fan_temp2=60000,fan_temp2_hyst=5000,fan_temp2_speed=200
dtparam=fan_temp3=70000,fan_temp3_hyst=5000,fan_temp3_speed=250

每行的意思,以第二行为例,cpu温度42度开始转,42-2度=40度时停止(下面几个是切换到低档位),转速80(最大255)
其他说明在/boot/overlays/README

使用root用户登录ssh

修改/etc/ssh/sshd_config,默认是第一行,下面添加第二行

1
2
#PermitRootLogin prohibit-password
PermitRootLogin yes

之后的命令有些需要root权限,普通用户运行前要加sudo

切换软件源

删除/etc/apt/sources.list内的内容
编辑/etc/apt/sources.list.d/raspi.list文件

1
2
3
4
5
6
7
8
9
10
11
12
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

deb http://mirrors.ustc.edu.cn/debian-security/ bookworm-security main contrib non-free non-free-firmware
~

更新软件源和软件

1
2
apt update
apt upgrade

安装常用软件

1
apt install vim python3-pip docker-compose

设置pip镜像地址

1
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

添加l命令,修改ls时间显示格式

编辑~/.bashrc添加

1
2
3
alias l='ls -ahl'
alias temp='vcgencmd measure_temp'
export TIME_STYLE='+%Y-%m-%d %H:%M:%S'

其他常用命令

1
2
3
4
# 查看cpu温度
vcgencmd measure_temp
# 设置时区
timedatectl set-timezone Asia/Shanghai

服务

webdav服务器

https://andi.wang/go?search=webdav

pm2.5检测系统

https://andi.wang/go?search=攀藤PMS5003ST

filebrowser网页文件管理程序

https://andi.wang/2022/01/26/%E4%BD%BF%E7%94%A8archlinux%E6%90%AD%E5%BB%BA%E5%AE%B6%E5%BA%AD%E6%95%B0%E6%8D%AE%E6%9C%8D%E5%8A%A1%E4%B8%AD%E5%BF%83/#filebrowser

离线签到

https://andi.wang/2022/01/26/%E4%BD%BF%E7%94%A8archlinux%E6%90%AD%E5%BB%BA%E5%AE%B6%E5%BA%AD%E6%95%B0%E6%8D%AE%E6%9C%8D%E5%8A%A1%E4%B8%AD%E5%BF%83/#%E7%AD%BE%E5%88%B0%E8%84%9A%E6%9C%AC

adminer数据库管理

下载主程序https://www.adminer.org/en/#download
下载sqlite无密码登录插件https://github.com/vrana/adminer/blob/master/plugins/login-password-less.php
下载sqlite登录页面https://github.com/vrana/adminer/blob/master/adminer/sqlite.php
三个文件放在同一个目录下
sqlite.php修改第3行,第6行修改成自己需要的密码,第10行改成adminer主程序的文件名

1
2
3
	include_once "./login-password-less.php";
new AdminerLoginPasswordLess(password_hash("123", PASSWORD_DEFAULT)),
include "./adminer-5.3.0.php";

浏览器访问sqlite.php,系统sqlite,用户名空,密码123(自己设置的密码),数据库填绝对路径,例如/srv/http/test/test.db
就可以进入数据库了

home-assistant智能家居(docker方式)

新建一个保存home-assistant文件的文件夹/srv/homeassistant

1
2
3
4
5
6
7
8
9
docker run -d \
--name homeassistant \
--privileged \
--restart=unless-stopped \
-e TZ=Asia/Shanghai \
-v /srv/homeassistant:/config \
-v /run/dbus:/run/dbus:ro \
--network=host \
ghcr.io/home-assistant/home-assistant:stable

编辑/srv/homeassistant/configuration.yaml,最后添加

1
2
3
4
5
http:
use_x_forwarded_for: true
trusted_proxies:
- 192.168.31.0/24
- 127.0.0.1

重启home assistant,docker restart homeassistant
浏览器访问ip:8123就有界面了,创建账号,进入主界面后,左下角点击自己账号,右侧高级模式,打开

安装hacs,添加小米设备

项目地址https://github.com/XiaoMi/ha_xiaomi_home
新建文件夹/srv/homeassistant/custom_components/hacs
下载hacs.zip,https://github.com/hacs/integration/releases,解压到hacs文件夹
重启home assistant,docker restart homeassistant
设置,设备与服务,右下角添加集成,hacs
打开提示的github页面,填写提示的8位验证码,完成
home assistant界面左侧出现HACS,点击,右边点Xiaomi Home,右下角download
重启home assistant,docker restart homeassistant
设置,设备与服务,已发现,xiaomi_home,添加,请点击此处进行登录,小米界面登陆
如果跳转到错误页面,把网址的ip修改成你的设备ip
添加选择家庭(xx个设备),home-assistant主界面概览就能看见小米设备了